package leetcode_401_500;

import jdk.nashorn.internal.runtime.FindProperty;

import javax.swing.*;

public class LeeCode_495 {
    public static void main(String[] args) {
        System.out.println(findPoisonedDuration(new int[]{1, 2}, 2));
        System.out.println(findPoisonedDuration(new int[]{1, 4}, 2));
    }
    private static int findPoisonedDuration(int[] timeSeries, int duration) {
        int ans = 0, ex = 0;
        for (int timeSery : timeSeries) {
            if (timeSery > ex) {
                ans += duration;
            } else {
                ans += timeSery + duration - ex;
            }
            ex = timeSery + duration;
        }
        return ans;
    }
}

